package com.lijian.shiro.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lijian.shiro.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: LiJian
 * @CreateTime: 2024-12-26
 * Description:
 */

@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT NAME FROM role WHERE id IN (SELECT rid FROM role_user WHERE uid=(SELECT id FROM user WHERE NAME=#{principal}))")
    List<String> getUserRoleInfoMapper(@Param("principal") String principal);
    //根据角色名查询对应权限信息
    @Select({
            "<script>", "select info FROM permissions WHERE id IN ",
            "(SELECT pid FROM role_ps WHERE rid IN (",
            "SELECT id FROM role WHERE NAME IN ",
            "<foreach collection='roles' item='name' open='(' separator=',' close=')'>", "#{name}", "</foreach>", "))",
            "</script>"
            })
    List<String> getUserPermissionInfoMapper(@Param("roles")List<String> roles);
}
